global root "/Volumes/Workgroup/Lab/Lab-heimb/Montenovo/Volunteering Paper/Data"
global results "$root/07_results/RR/main"
global dictionaries "$root/Dictionaries"

cd "$root"
use appended_analytic_010305111719, clear 

gen log_taxprice=log(taxprice)
gen log_post_tax_income=log(post_tax_income)
gen log_hourly_wage_aftertax=log(hourly_wage_aftertax)

label variable log_taxprice "Log(Tax Price)"
label variable log_post_tax_income "Log(Post Tax Income)"
label variable log_hourly_wage_aftertax "Log(After Tax Hourly Wage)"

*extensive, no fe
eststo extensive_margin: reghdfe whether_volunteer_person  log_taxprice log_post_tax_income log_hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, noabsorb vce(cluster state)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals
*extensive, yr fe
eststo extensive_margin_yrfe: reghdfe whether_volunteer_person  log_taxprice log_post_tax_income log_hourly_wage_aftertax full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year) vce(cluster state)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals
*extensive, year state fe
eststo extensive_margin_stfe: reghdfe whether_volunteer_person   log_taxprice log_post_tax_income log_hourly_wage_aftertax  full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state) vce(cluster state)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

*extensive, year state individual fe
eststo extensive_margin_fe: reghdfe whether_volunteer_person   log_taxprice log_post_tax_income log_hourly_wage_aftertax  full_time age sex  married black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural, absorb(year state unique_id_crossys) vce(cluster state)
gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

cd "$results"

	 esttab extensive_margin extensive_margin_yrfe extensive_margin_stfe extensive_margin_fe using "preliminary_extensive_logs.rtf", se star(* 0.10 ** 0.05 *** 0.01) replace se(a4) b(a3) title("Extensive Margin") addnotes("Outcome Variable: Whether person volunteered" "Col 1: No FE" "Col 2: Year FE" "Col 3: Year FE and State FE" "Col 4: Year, State, Individual FE") modelwidth(12) label cells(b(star fmt(3)) se(par fmt(3)))

	 eststo extensive_margin_sm: reghdfe whether_volunteer_person  log_taxprice log_post_tax_income log_hourly_wage_aftertax  full_time  age black native_amer asian other hispanic HS some_college college_grad college_plus children  religion rural if (sex==1 & sequence_num==1 & married==0), absorb(year state unique_id_crossys) vce(cluster state)

sum whether_volunteer_person if sex==1 & sequence_num==1 & married==0

gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

*extensive, year state family fe - single female
eststo extensive_margin_sf: reghdfe whether_volunteer_person  log_taxprice log_post_tax_income log_hourly_wage_aftertax  full_time  age    black native_amer asian other hispanic HS some_college college_grad college_plus children  religion rural if (sex==2 & sequence_num==1 & married==0), absorb(year state unique_id_crossys) vce(cluster state)
// (dropped 3327 singleton observations)

gen extensive_margin_sf=e(sample)
sum whether_volunteer_person if sex==2 & sequence_num==1 & married==0

gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals


//bysort family_id year state: egen sum_singlefemale=sum(c) if single_female==1
//tab sum_singlefemale

*extensive, year state family fe - married male
eststo extensive_margin_mm: reghdfe whether_volunteer_person  log_taxprice log_post_tax_income log_hourly_wage_aftertax  full_time  age    black native_amer asian other hispanic HS some_college college_grad college_plus children  religion rural if (sex==1 & married==1), absorb(year state unique_id_crossys) vce(cluster state)
// (dropped 2049 singleton observations)

gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals


//bysort family_id year state: egen sum_marriedmale=sum(c) if married_male==1
//tab sum_marriedmale

*extensive, year state family fe - married female
eststo extensive_margin_mf: reghdfe whether_volunteer_person  log_taxprice log_post_tax_income log_hourly_wage_aftertax  full_time  age    black native_amer asian other hispanic HS some_college college_grad college_plus children religion rural if (sex==2 & married==1), absorb(year state unique_id_crossys) vce(cluster state)
// (dropped 2067 singleton observations)

gen sample=e(sample)
bysort unique_id_crossys: gen nvals=_n==1
count if nvals==1 & sample==1
drop sample nvals

cd "$results"

	 esttab extensive_margin_sm extensive_margin_sf extensive_margin_mm extensive_margin_mf using "regress_extensive_gender_mstat_logs.rtf", se star(* 0.10 ** 0.05 *** 0.01) replace se(a4) b(a3) title("Extensive Margin for Single Male, Single Female, Married Male and Married Female") addnotes("Col 1: Single Male" "Col 2: Single Female" "Col 3: Married Male" "Col 4: Married Female" "All Models include Year, State, and Individual FE") modelwidth(12) label cells(b(star fmt(3)) se(par fmt(3)))


	 
	